package com.spring.shops.admin.controller.menu;

import com.spring.shops.context.BaseContext;
import com.spring.shops.dao.TzSysUserMapper;
import com.spring.shops.model.entity.TzSysUser;
import com.spring.shops.model.result.ServerResponseEntityVoid;
import com.spring.shops.model.vo.SysUserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
@RestController
//指定返回的数据类型为json并且字符集为utf-8
@RequestMapping(value="/sys/user",produces = "application/json; charset=utf-8")
public class SysUserController {
    @Autowired
    private TzSysUserMapper mapper;
    @GetMapping("/info")
    public ServerResponseEntityVoid<SysUserVO> getInfo(){
        //根据当前用户id获取用户名
        TzSysUser tzSysUser = mapper.selectByPrimaryKey(BaseContext.getCurrentId());
        SysUserVO user = new SysUserVO();
        user.setUserId(tzSysUser.getUserId());
        user.setUsername(tzSysUser.getUsername()+"！您好");
        user.setEmail(tzSysUser.getEmail());
        user.setMobile(tzSysUser.getMobile());
        user.setStatus(tzSysUser.getStatus());
        user.setShopId(tzSysUser.getShopId());
        user.setRoleIdList(null);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = sdf.format(tzSysUser.getCreateTime());
        user.setCreateTime(format);
        return ServerResponseEntityVoid.success(user);

    }

}
